package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

// https://www.jianshu.com/p/8061bceb4500
// https://blog.csdn.net/llll234/article/details/80966952
// https://blog.csdn.net/niuchenliang524/article/details/81326238
// 定时器
@EnableScheduling
@Component
public class TestSenderController {

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	//向redis消息队列index通道发布消息
//	@Scheduled(fixedRate = 2000)
	public void sendMessage() {
		
		stringRedisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Message.class));

		stringRedisTemplate.convertAndSend("pmp", Message.builder().name("pmp").build());

		stringRedisTemplate.convertAndSend("channel", Message.builder().name("channel").build());
	}
}